using System;
using Kiwi.Container.Internal;

namespace Kiwi.Container.Activation
{
    public class LambdaComponentActivator<T, C> : IComponentActivator<C> where C : T
    {
        private readonly Func<IComponentResolver, C> _creator;

        public LambdaComponentActivator(Func<IComponentResolver, C> creator)
        {
            _creator = creator;
        }

        #region IComponentActivator<C> Members

        public object ActivateComponent(IComponentResolver resolver)
        {
            var component = _creator(resolver);
            if (component == null)
            {
                Throw.ActivatedComponentNull(typeof (T), typeof (C));
            }
            return component;
        }

        #endregion
    }
}